<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>{:t('优惠券')}设置</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  {include file="public/css"/}
</head>
<body>
  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
      <div class="layui-card layui-col-md12">
				<div class="layui-card-header">
					{if !$info['id']}<i class="fa fa-plus"></i> 添加{:t('优惠券')}{else}<i class="fa fa-pencil"></i> 编辑{:t('优惠券')}{/if}
					<i class="layui-icon layui-icon-close" style="font-size:18px;font-weight:bold;cursor:pointer" onclick="closeself()"></i>
				</div>
				<div class="layui-card-body" pad15>
					<div class="layui-form" lay-filter="">
						<input type="hidden" name="info[id]" value="{$info['id']}">
						<div class="layui-form-item">
							<label class="layui-form-label" style="width:100px">所属商户：</label>
							<div class="layui-input-inline">
								<select name="info[bid]" lay-verify="required" lay-verType="tips">
								<option value="">--请选择--</option>
								{foreach $blist as $bv}
									<option value="{$bv['id']}" {if $bv['id']==$info['bid']}selected{/if}>{$bv['name']}</option>
								{/foreach}
								</select>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label" style="width:100px">{:t('优惠券')}类型：</label>
							<div class="layui-input-inline" style="width:500px">
								<input type="radio" name="info[type]" value="1" title="代金券" {if !$info['id'] || $info['type']==1}checked{/if} lay-filter="coupon_type">
								<input type="radio" name="info[type]" value="2" title="礼品券" {if $info['type'] && $info['type']==2}checked{/if} lay-filter="coupon_type">
								<input type="radio" name="info[type]" value="3" title="计次券" {if $info['type'] && $info['type']==3}checked{/if} lay-filter="coupon_type">
								<input type="radio" name="info[type]" value="4" title="运费抵扣券" {if $info['type'] && $info['type']==4}checked{/if} lay-filter="coupon_type">
							</div>
							<div class="layui-word-aux" style="clear:both;margin-left:125px">代金券：可以直接抵扣金额使用；礼品券：用于兑换实物奖品等场景；计次券：用于可以多次使用的{:t('优惠券')}场景，如：理发店计次卡等；运费抵扣券：用于在线购买时抵扣运费</div>
						</div>

						<div class="layui-form-item">
							<label class="layui-form-label" style="width:100px">{:t('优惠券')}名称：</label>
							<div class="layui-input-inline">
								<input type="text" name="info[name]" value="{$info.name}" lay-verify="required" lay-verType="tips" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-form-item coupon_type1" {if $info['id'] && $info['type']!=1}style="display:none"{/if}>
							<label class="layui-form-label" style="width:100px">优惠金额：</label>
							<div class="layui-input-inline">
								<input type="text" name="info[money]" value="{$info.money}" autocomplete="off" class="layui-input">
							</div>
							<div class="layui-form-mid">元</div>
							<div class="layui-word-aux" style="clear:both;margin-left:125px">注：用于商品订单抵扣时，{:t('优惠券')}只能抵消商品金额，不能抵消运费</div>
						</div>
						<div class="layui-form-item coupon_type1" {if $info['id'] && $info['type']!=1}style="display:none"{/if}>
							<label class="layui-form-label" style="width:100px">最低消费金额：</label>
							<div class="layui-input-inline">
								<input type="text" name="info[minprice]" value="{$info.minprice|default=0}" lay-verify="required" lay-verType="tips" autocomplete="off" class="layui-input">
							</div>
							<div class="layui-form-mid">元</div>
							<div class="layui-word-aux" style="clear:both;margin-left:125px"> 注：购物金额（不含运费）达到最低消费金额才可使用{:t('优惠券')}，无门槛{:t('优惠券')}请填0</div>
						</div>
						

						<div class="layui-form-item coupon_type3" {if $info['type']!=3}style="display:none"{/if}>
							<label class="layui-form-label" style="width:100px">可用次数：</label>
							<div class="layui-input-inline">
								<input type="number" name="info[limit_count]" value="{$info.limit_count|default=10}" autocomplete="off" class="layui-input">
							</div>
							<div class="layui-form-mid">次</div>
							<div class="layui-form-mid layui-word-aux">每张券可以使用多少次</div>
						</div>
						<div class="layui-form-item coupon_type3" {if $info['type']!=3}style="display:none"{/if}>
							<label class="layui-form-label" style="width:100px">每天可用：</label>
							<div class="layui-input-inline">
								<input type="number" name="info[limit_perday]" value="{$info.limit_perday|default=0}" autocomplete="off" class="layui-input">
							</div>
							<div class="layui-form-mid">次</div>
							<div class="layui-form-mid layui-word-aux">每张券每天最多可以使用多少次，0表示不限制</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label" style="width:100px">使用说明：</label>
							<div class="layui-input-inline" style="width:300px">
								<textarea name="info[usetips]" class="layui-textarea">{$info.usetips}</textarea>
							</div>
							<div class="layui-form-mid layui-word-aux"></div>
						</div>

						<div class="layui-form-item">
							<label class="layui-form-label" style="width:100px">有效期：</label>
							<div class="layui-input-inline" style="width:500px">
								<input type="radio" name="info[yxqtype]" value="1" title="固定时间范围" {if !$info['id'] || $info['yxqtype']==1}checked{/if} lay-filter="yxqtype"/>
								<input type="radio" name="info[yxqtype]" value="2" title="领取后时长" {if $info['yxqtype']==2}checked{/if} lay-filter="yxqtype"/>
								<input type="radio" name="info[yxqtype]" value="3" title="领取后时长（次日起）" {if $info['yxqtype']==3}checked{/if} lay-filter="yxqtype"/>
							</div>
						</div>
						<div class="layui-form-item yxqtimeitem" id="yxqtimeitem_1" {if $info['id'] && $info['yxqtype']!=1}style="display:none"{/if}>
							<label class="layui-form-label" style="width:100px"></label>
							<div class="layui-form-mid">有效期时间</div>
							<div class="layui-input-inline" style="width:300px">
								<input type="text" name="info[yxqtime]" value="{$info.yxqtime}" id="yxqtime" class="layui-input"/>
							</div>
						</div>
						<div class="layui-form-item yxqtimeitem" id="yxqtimeitem_2" {if $info['yxqtype']!=2}style="display:none"{/if}>
							<label class="layui-form-label" style="width:100px"></label>
							<div class="layui-form-mid">领取后</div>
							<div class="layui-input-inline" style="width:70px">
								<input type="text" name="yxqdate2" value="{$info.yxqdate}" class="layui-input"/>
							</div>
							<div class="layui-form-mid">天内有效</div>
						</div>
					  <div class="layui-form-item yxqtimeitem" id="yxqtimeitem_3" {if $info['yxqtype']!=3}style="display:none"{/if}>
						  <label class="layui-form-label" style="width:100px"></label>
						  <div class="layui-form-mid">领取后</div>
						  <div class="layui-input-inline" style="width:70px">
							  <input type="text" name="yxqdate3" value="{$info.yxqdate}" class="layui-input"/>
						  </div>
						  <div class="layui-form-mid">天内有效（次日0点开始计算有效期）</div>
					  </div>
						
						<div class="layui-form-item">
							<label class="layui-form-label" style="width:110px"><span class="redstar">*</span>参与条件：</label>
							<div class="layui-input-inline" style="width:500px">
								<input type="checkbox" name="info[gettj][]" value="-1" title="所有人" {if in_array('-1',$info['gettj'])}checked{/if}/>
								<!-- <input type="checkbox" name="info[gettj][]" value="0" title="关注用户" {if in_array('0',$info['gettj'])}checked{/if}/> -->
								{foreach $memberlevel as $v}
								<input type="checkbox" name="info[gettj][]" value="{$v.id}" title="{$v.name}" {if in_array($v['id'],$info['gettj'])}checked{/if}/>
								{/foreach}
							</div>
						</div>
						
						<div class="layui-form-item">
							<label class="layui-form-label" style="width:100px">所需金额：</label>
							<div class="layui-input-inline">
								<input type="text" name="info[price]" value="{$info.price|default=0}" lay-verify="required" lay-verType="tips" autocomplete="off" class="layui-input">
							</div>
							<div class="layui-form-mid layui-word-aux">需要消耗多少钱购买</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label" style="width:100px">所需{:t('积分')}：</label>
							<div class="layui-input-inline">
								<input type="text" name="info[score]" value="{$info.score|default=0}" lay-verify="required" lay-verType="tips" autocomplete="off" class="layui-input">
							</div>
							<div class="layui-form-mid layui-word-aux">需要消耗多少{:t('积分')}兑换</div>
						</div>

						<div class="layui-form-item">
							<label class="layui-form-label" style="width:100px">库存：</label>
							<div class="layui-input-inline">
								<input type="text" name="info[stock]" value="{$info.stock|default=100}" class="layui-input">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label" style="width:100px">每人可领取数：</label>
							<div class="layui-input-inline">
								<input type="text" name="info[perlimit]" value="{$info['perlimit']}" class="layui-input">
							</div>
							<div class="layui-form-mid layui-word-aux">每人最多可领取多少张</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label" style="width:100px">开始时间：</label>
							<div class="layui-input-inline">
								<input type="text" name="info[starttime]" autocomplete="off" value="{$info.starttime}" lay-verify="required" lay-verType="tips" class="layui-input" id="starttime">
							</div>
							<div class="layui-form-mid layui-word-aux">活动开始时间</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label" style="width:100px">结束时间：</label>
							<div class="layui-input-inline">
								<input type="text" name="info[endtime]" autocomplete="off" value="{$info.endtime}" lay-verify="required" lay-verType="tips" class="layui-input" id="endtime">
							</div>
							<div class="layui-form-mid layui-word-aux">活动结束时间</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label" style="width:100px">序号：</label>
							<div class="layui-input-inline">
								<input type="text" name="info[sort]" value="{$info.sort}" class="layui-input">
							</div>
							<div class="layui-form-mid layui-word-aux" style="margin-left:10px;">用于排序,越大越靠前</div>
						</div>
						
						<div class="layui-form-item">
							<label class="layui-form-label" style="width:100px">可直接领取：</label>
							<div class="layui-input-inline">
								<input type="radio" name="info[tolist]" value="1" {if !$info['id'] || $info['tolist']==1}checked{/if} title="是"/>
								<input type="radio" name="info[tolist]" value="0" {if $info['id'] && $info['tolist']==0}checked{/if} title="否"/>
							</div>
							<div class="layui-form-mid layui-word-aux" style="margin-left:10px;">是否可以在领券中心直接领取</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label" style="width:100px">支付后赠送：</label>
							<div class="layui-input-inline">
								<input type="radio" name="info[paygive]" value="0" {if !$info['id'] || $info['paygive']==0}checked{/if} title="关闭" lay-filter="paygive"/>
								<input type="radio" name="info[paygive]" value="1" {if $info['id'] && $info['paygive']==1}checked{/if} title="开启" lay-filter="paygive"/>
							</div>
							<div class="layui-form-mid layui-word-aux" style="margin-left:10px;">支付成功后自动发放{:t('优惠券')}</div>
						</div>
						<div style="{if !$info['id'] || $info['paygive']==0}display:none{/if}" id="paygiveset">
							<div class="layui-form-item">
								<label class="layui-form-label" style="width:100px">支付赠送场景：</label>
								<div class="layui-input-inline" style="width:600px">
									{php} $paygive_scenes = explode(',',$info['paygive_scene']);{/php}
									<input type="checkbox" name="info[paygive_scene][]" value="shop" {if in_array('shop',$paygive_scenes)}checked{/if} title="商城"/>
									<input type="checkbox" name="info[paygive_scene][]" value="scoreshop" {if in_array('scoreshop',$paygive_scenes)}checked{/if} title="兑换"/>
									<input type="checkbox" name="info[paygive_scene][]" value="collage" {if in_array('collage',$paygive_scenes)}checked{/if} title="拼团"/>
									<input type="checkbox" name="info[paygive_scene][]" value="kanjia" {if in_array('kanjia',$paygive_scenes)}checked{/if} title="砍价"/>
									<input type="checkbox" name="info[paygive_scene][]" value="recharge" {if in_array('recharge',$paygive_scenes)}checked{/if} title="充值"/>
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label" style="width:100px">支付最低金额：</label>
								<div class="layui-input-inline">
									<input type="text" name="info[paygive_minprice]" value="{$info.paygive_minprice|default=0}" class="layui-input">
								</div>
								<div class="layui-form-mid">元</div>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label" style="width:100px">购买商品赠送：</label>
							<div class="layui-input-inline" style="width:500px">
								<input type="radio" name="info[buyprogive]" value="0" {if $info['buyprogive']==0}checked{/if} title="关闭" lay-filter="buyprogive"/>
								<input type="radio" name="info[buyprogive]" value="1" {if $info['buyprogive']==1}checked{/if} title="开启" lay-filter="buyprogive"/>
							</div>
							<div class="buyprogive" style="clear:both;{if $info['buyprogive']!=1}display:none{/if}">
								<label class="layui-form-label" style="width:100px"></label>
								<div class="layui-input-inline" style="width:auto">
									<table  class="layui-table" style="width:500px">
										<thead>
										<tr>
											<th>商品ID</th>
											<th>商品名称</th>
											<th>操作</th>
										</tr>
										</thead>
										{if $productdata2}
										{foreach $productdata2 as $k=>$ff}
										<tr class="productlisttr2"><td>{$ff.id}</td><td>{$ff.name}</td><td><button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="delProduct2(this,{$ff.id})">删除</button></td></tr>
										{/foreach}
										{/if}
										<tr id="productaddtr2">
											<td colspan="3"><button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="showChooseProduct2()">添加</button></td>
										</tr>
									</table>
									<input type="hidden" name="info[buyproids]" value="{$info.buyproids}"/>
								</div>
							</div>
							<script>
							var chooseProductLayer2;
							function showChooseProduct2(){
								chooseProductLayer2 = layer.open({type:2,title:'选择商品',content:"{:url('ShopProduct/chooseproduct')}/type/2",area:['1000px','600px'],shadeClose:true});
							}
							function choosepro2(res){
								var product = res.product
								layer.close(chooseProductLayer2);
								var buyproids = [];
								var isadd = 0;
								$('.productlisttr2').each(function(){
									var thisfid = $(this).find('td:eq(0)').html();
									if(thisfid == product.id){
										isadd = 1
										dialog('该商品已添加过了');
									}
									buyproids.push(thisfid)
								})
								if(isadd == 0){
									buyproids.push(product.id)
									$("input[name='info[buyproids]']").val(buyproids.join(','));
									$('#productaddtr2').before('<tr class="productlisttr2"><td>'+product.id+'</td><td>'+product.name+'</td><td><button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="delProduct2(this,'+product.id+')">删除</button></td></tr>');
								}
								console.log(buyproids)
							}
							function delProduct2(obj,fid){
								$(obj).parent().parent().remove();
								var buyproids = [];
								$('.productlisttr2').each(function(){
									buyproids.push($(this).find('td:eq(0)').html())
								})
								$("input[name='info[buyproids]']").val(buyproids.join(','));
							}
							</script>
						</div>
						
						<div class="layui-form-item">
							<div class="layui-input-block" style="margin-left:130px;">
								<button class="layui-btn" lay-submit lay-filter="formsubmit">提 交</button>
							</div>
						</div>
					</div>
				</div>
      </div>
    </div>
  </div>
	{include file="public/js"/}
	<script>
	layui.form.on('radio(coupon_type)',function(data){
		if(data.value==1){
			$('.coupon_type1').show();
			$('.coupon_type2').hide();
			$('.coupon_type3').hide();
			$('.coupon_type4').hide();
		}
		if(data.value == 2){
			$('.coupon_type1').hide();
			$('.coupon_type2').show();
			$('.coupon_type3').hide();
			$('.coupon_type4').hide();
		}
		if(data.value == 3){
			$('.coupon_type1').hide();
			$('.coupon_type2').hide();
			$('.coupon_type3').show();
			$('.coupon_type4').hide();
		}
		if(data.value == 4){
			$('.coupon_type1').hide();
			$('.coupon_type2').hide();
			$('.coupon_type3').hide();
			$('.coupon_type4').show();
		}
	});
	layui.form.on('radio(buyprogive)',function(data){
		if(data.value==1){
			$('.buyprogive').show();
		}else{
			$('.buyprogive').hide();
		}
	})
	layui.form.on('radio(yxqtype)',function(data){
		if(data.value==1){
			$('#yxqtimeitem').show();
			$('#yxqdateitem').hide();
		}else{
			$('#yxqtimeitem').hide();
			$('#yxqdateitem').show();
		}
	})
	layui.form.on('radio(paygive)',function(data){
		if(data.value==1){
			$('#paygiveset').show();
		}else{
			$('#paygiveset').hide();
		}
	})
	layui.laydate.render({ 
		elem: '#starttime'
		,type: 'datetime'
		,range: false,
		trigger: 'click'
	});
	layui.laydate.render({ 
		elem: '#endtime'
		,type: 'datetime'
		,range: false,
		trigger: 'click'
	});
	layui.laydate.render({ 
		elem: '#yxqtime'
		,type: 'datetime'
		,range: '~',
		trigger: 'click'
	});

	layui.form.on('submit(formsubmit)', function(obj){
		var field = obj.field
		var index = layer.load();
		$.post("{:url('save')}",field,function(data){
			layer.close(index);
			dialog(data.msg,data.status);
			if(data.status == 1){
				setTimeout(function(){
					parent.layer.closeAll();
					parent.tableIns.reload()
				},1000)
			}
		})
	})
  </script>
	{include file="public/copyright"/}
</body>
</html>